home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_jade.idb / usr / freeware / include / sp / generic / SGMLApplication.h.z / SGMLApplication.h
C/C++ Source or Header  |  1999-07-21  |  8KB  |  313 lines

  1. // Copyright (c) 1995 James Clark
  2. // See the file COPYING for copying permission.
  3.  
  4. #ifndef SGMLApplication_INCLUDED
  5. #define SGMLApplication_INCLUDED 1
  6.  
  7. #ifdef __GNUG__
  8. #pragma interface
  9. #endif
  10.  
  11. #include <stddef.h>
  12.  
  13. #ifndef SP_API
  14. #define SP_API /* as nothing */
  15. #endif
  16.  
  17. class SP_API SGMLApplication {
  18. public:
  19. #ifdef SP_MULTI_BYTE
  20. #ifdef SP_WCHAR_T_USHORT
  21.   typedef wchar_t Char;
  22. #else
  23.   typedef unsigned short Char;
  24. #endif
  25. #else
  26.   typedef unsigned char Char;
  27. #endif
  28.   // A Position represents a position in an OpenEntity.
  29.   // The meaning of a Position depends on the
  30.   // particular implementation of OpenEntity.
  31.   // It might be a line number or it might be
  32.   // an offset in the entity.  The only thing
  33.   // that can be done with Position is to use
  34.   // it with an OpenEntityPtr to get a Location.
  35.   typedef unsigned long Position;
  36.   struct CharString {
  37.     const Char *ptr;
  38.     size_t len;
  39.   };
  40.   struct ExternalId {
  41.     bool haveSystemId;
  42.     bool havePublicId;
  43.     bool haveGeneratedSystemId;
  44.     CharString systemId;    // valid only if haveSystemId is true
  45.     CharString publicId;    // valid only if havePublicId is true
  46.     CharString generatedSystemId; // valid if haveGeneratedSystemId is true
  47.   };
  48.   struct Notation {
  49.     CharString name;
  50.     ExternalId externalId;
  51.   };
  52.   struct Attribute;
  53.   struct Entity {
  54.     CharString name;
  55.     enum DataType { sgml, cdata, sdata, ndata, subdoc, pi };
  56.     enum DeclType { general, parameter, doctype, linktype };
  57.     DataType dataType;
  58.     DeclType declType;
  59.     bool isInternal;
  60.     // Following valid if isInternal is true
  61.     CharString text;
  62.     // Following valid if isInternal is false
  63.     ExternalId externalId;
  64.     size_t nAttributes;
  65.     const Attribute *attributes;
  66.     Notation notation;
  67.   };
  68.   struct Attribute {
  69.     CharString name;
  70.     enum Type {
  71.       invalid,
  72.       implied,
  73.       cdata,
  74.       tokenized
  75.       };
  76.     Type type;
  77.     enum Defaulted {
  78.       specified,        // not defaulted
  79.       definition,        // defaulted from definition
  80.       current            // defaulted from current value
  81.       };
  82.     Defaulted defaulted;    // non-ESIS; valid only if type != implied
  83.     struct CdataChunk {
  84.       bool isSdata;
  85.       // This rather awkward representation of non-SGML characters was chosen
  86.       // for backwards compatibility.
  87.       bool isNonSgml;        // valid only if !isSdata
  88.       Char nonSgmlChar;        // valid only if isNonSgml
  89.       CharString data;        // always valid; empty if isNonSgml
  90.       CharString entityName;    // non-ESIS; optional for SDATA chunks
  91.     };
  92.     // Following valid if type == cdata
  93.     size_t nCdataChunks;
  94.     const CdataChunk *cdataChunks; // valid if type == cdata
  95.     // Following valid if type == tokenized
  96.     CharString tokens; // separated by spaces
  97.     bool isId;           // non-ESIS (probably)
  98.     bool isGroup;      // non-ESIS
  99.     size_t nEntities;
  100.     const Entity *entities;
  101.     // length of notation.name will be 0 if no notation
  102.     Notation notation;
  103.   };
  104.   struct PiEvent {
  105.     Position pos;
  106.     CharString data;
  107.     CharString entityName;    // non-ESIS; optional for PI entities
  108.   };
  109.   struct StartElementEvent {
  110.     Position pos;
  111.     enum ContentType {
  112.       empty,            // declared EMPTY or with CONREF attribute
  113.       cdata,
  114.       rcdata,
  115.       mixed,
  116.       element
  117.       };
  118.     CharString gi;
  119.     ContentType contentType;    // non-ESIS
  120.     bool included;        // non-ESIS
  121.     size_t nAttributes;
  122.     const Attribute *attributes;
  123.   };
  124.       
  125.   struct EndElementEvent {
  126.     Position pos;
  127.     CharString gi;
  128.   };
  129.   struct DataEvent {
  130.     Position pos;
  131.     CharString data;
  132.   };
  133.   struct SdataEvent {
  134.     Position pos;
  135.     CharString text;
  136.     CharString entityName;    // non-ESIS; optional
  137.   };
  138.   struct ExternalDataEntityRefEvent {
  139.     Position pos;
  140.     Entity entity;
  141.   };
  142.   struct SubdocEntityRefEvent {
  143.     Position pos;
  144.     Entity entity;
  145.   };
  146.   struct NonSgmlCharEvent {
  147.     Position pos;
  148.     Char c;
  149.   };
  150.   struct ErrorEvent {
  151.     Position pos;
  152.     enum Type {
  153.       info,            // not an error
  154.       warning,            // not an error
  155.       quantity,
  156.       idref,
  157.       capacity,
  158.       otherError
  159.       };
  160.     Type type;
  161.     CharString message;
  162.   };
  163.   struct AppinfoEvent {
  164.     Position pos;
  165.     bool none;
  166.     CharString string;
  167.   };
  168.   struct StartDtdEvent {
  169.     Position pos;
  170.     CharString name;
  171.     bool haveExternalId;
  172.     ExternalId externalId;
  173.   };
  174.   struct EndDtdEvent {
  175.     Position pos;
  176.     CharString name;
  177.   };
  178.   struct EndPrologEvent {
  179.     Position pos;
  180.   };
  181.   // non-ESIS
  182.   struct GeneralEntityEvent {
  183.     // no position
  184.     Entity entity;
  185.   };
  186.   // non-ESIS
  187.   struct CommentDeclEvent {
  188.     Position pos;
  189.     size_t nComments;
  190.     const CharString *comments;
  191.     const CharString *seps;
  192.   };
  193.   // non-ESIS
  194.   struct MarkedSectionStartEvent {
  195.     Position pos;
  196.     enum Status {
  197.       include,
  198.       rcdata,
  199.       cdata,
  200.       ignore
  201.     };
  202.     Status status;
  203.     struct Param {
  204.       enum Type {
  205.     temp,
  206.     include,
  207.     rcdata,
  208.     cdata,
  209.     ignore,
  210.     entityRef
  211.     };
  212.       Type type;
  213.       CharString entityName;
  214.     };
  215.     size_t nParams;
  216.     const Param *params;
  217.   };
  218.   // non-ESIS
  219.   struct MarkedSectionEndEvent {
  220.     Position pos;
  221.     enum Status {
  222.       include,
  223.       rcdata,
  224.       cdata,
  225.       ignore
  226.     };
  227.     Status status;
  228.   };
  229.   struct IgnoredCharsEvent {
  230.     Position pos;
  231.     CharString data;
  232.   };
  233.   class OpenEntityPtr;
  234.   struct SP_API Location {
  235.     Location();
  236.     Location(const OpenEntityPtr &, Position);
  237.     void init();
  238.  
  239.     unsigned long lineNumber;
  240.     unsigned long columnNumber;
  241.     unsigned long byteOffset;
  242.     unsigned long entityOffset;
  243.     CharString entityName;
  244.     CharString filename;
  245.     const void *other;
  246.   };
  247.   class OpenEntity;
  248.   class SP_API OpenEntityPtr {
  249.   public:
  250.     OpenEntityPtr();
  251.     OpenEntityPtr(const OpenEntityPtr &);
  252.     void operator=(const OpenEntityPtr &);
  253.     void operator=(OpenEntity *);
  254.     ~OpenEntityPtr();
  255.     const OpenEntity *operator->() const;
  256.     operator int() const;
  257.   private:
  258.     OpenEntity *ptr_;
  259.   };
  260.   class SP_API OpenEntity {
  261.   public:
  262.     OpenEntity();
  263.     virtual ~OpenEntity();
  264.     virtual Location location(Position) const = 0;
  265.   private:
  266.     OpenEntity(const OpenEntity &); // undefined
  267.     void operator=(const OpenEntity &);    // undefined
  268.     unsigned count_;
  269.     friend class OpenEntityPtr;
  270.   };
  271.   virtual ~SGMLApplication();
  272.   virtual void appinfo(const AppinfoEvent &);
  273.   virtual void startDtd(const StartDtdEvent &);
  274.   virtual void endDtd(const EndDtdEvent &);
  275.   virtual void endProlog(const EndPrologEvent &);
  276.   virtual void startElement(const StartElementEvent &);
  277.   virtual void endElement(const EndElementEvent &);
  278.   virtual void data(const DataEvent &);
  279.   virtual void sdata(const SdataEvent &);
  280.   virtual void pi(const PiEvent &);
  281.   virtual void externalDataEntityRef(const ExternalDataEntityRefEvent &);
  282.   virtual void subdocEntityRef(const SubdocEntityRefEvent &);
  283.   virtual void nonSgmlChar(const NonSgmlCharEvent &);
  284.   virtual void commentDecl(const CommentDeclEvent &);
  285.   virtual void markedSectionStart(const MarkedSectionStartEvent &);
  286.   virtual void markedSectionEnd(const MarkedSectionEndEvent &);
  287.   virtual void ignoredChars(const IgnoredCharsEvent &);
  288.   virtual void generalEntity(const GeneralEntityEvent &);
  289.   virtual void error(const ErrorEvent &);
  290.   virtual void openEntityChange(const OpenEntityPtr &);
  291. };
  292.  
  293. inline
  294. const SGMLApplication::OpenEntity *
  295. SGMLApplication::OpenEntityPtr::operator->() const
  296. {
  297.   return ptr_;
  298. }
  299.  
  300. inline
  301. void SGMLApplication::OpenEntityPtr::operator=(const OpenEntityPtr &ptr)
  302. {
  303.   *this = ptr.ptr_;
  304. }
  305.  
  306. inline
  307. SGMLApplication::OpenEntityPtr::operator int() const
  308. {
  309.   return ptr_ != 0;
  310. }
  311.  
  312. #endif /* not SGMLApplication_INCLUDED */
  313.